package com.study.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * @author csc
 * @version 1.0.0
 * @create 2024/12/27 11:49
 * @Descriotion: 类的作用
 */
@Configuration
@EnableAsync
public class AsyncConfig {
    // 这里可以配置线程池等
    @Bean(name = "taskExecutor")
    public Executor taskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        executor.setCorePoolSize(5); // 核心线程数
        executor.setMaxPoolSize(10); // 最大线程数
        executor.setQueueCapacity(25); // 当线程数达到核心线程数时的队列容量
        executor.setThreadNamePrefix("AsyncThread-"); // 线程名称前缀
        executor.initialize();
        return executor;
    }
    
}